<template>
  <div class="container">
    <div class="mainBox">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-col :lg="8" :xl="6">
            <el-form-item label="添加日期" class="row-padding-bottom">
              <el-date-picker
                v-model="date"
                type="daterange"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="工资卡" class="row-padding-bottom">
              <el-select v-model="filterField.hasAccount" filterable clearable>
                <el-option
                  v-for="item in hasAccountOptions"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="劳动合同" class="row-padding-bottom">
                <el-select v-model="filterField.hasFile" filterable clearable>
                  <el-option
                    v-for="item in hasFileOptions"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="是否在职" class="row-padding-bottom">
                <el-select v-model="filterField.status" filterable clearable>
                  <el-option
                    v-for="item in hasJob"
                    :key="item.id"
                    :label="item.text"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :lg="8" :xl="6">
              <!-- <el-row> -->
            </el-col>
            <el-col :lg="8" :xl="6">
              <el-form-item label="员工" class="row-padding-bottom">
                <el-input
                  placeholder="请输入姓名或身份证号"
                  clearable
                  v-model="filterField.keyword"
                  @blur="filterField.keyword = changeValue($event)"
                ></el-input>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
            <el-form-item>
              <exportBtn
                :dataLen="employeeoutList.length"
                :filterField="filterField"
                api="api-s/report/export_JC_NC_EMPLOYEE"
              ></exportBtn>
            </el-form-item>
          </el-col>
          <!-- <el-form-item>
                            <el-button type="primary" icon="icon iconfont iconchazhao1" @click="searchList" class="commonBtn"></el-button>
                        </el-form-item> -->
          <!-- </el-row> -->
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <el-table
          :data="employeeoutList"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
          v-loading="loading"
        >
          <el-table-column prop="name,idcard" label="人员" min-width="120">
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="toEmployeeDetail(scope.$index, scope.row)"
                >{{ scope.row.name }}</el-link
              >
              <!-- <p class="toDownload" @click="toEmployeeDetail(scope.$index, scope.row)">{{scope.row.name}}</p> -->
              <p>{{ scope.row.idcard | deseHandler(4, 4, '*') || '--' }}</p>
              <p>
                {{ scope.row.orgName }}
                <span v-if="scope.row.employeeType">/</span
                >{{ scope.row.employeeType }}
              </p>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="添加日期"
            align="center"
            min-width="70"
          ></el-table-column>
          <el-table-column
            prop="startDate,endDate"
            label="雇佣周期"
            align="center"
            min-width="120"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.startDate }}-{{ scope.row.endDate }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="overDate"
            label="离职日期"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <el-table-column
            prop="bankName,accountId"
            label="工资卡"
            align="center"
            min-width="120"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.bankName }}</p>
              <p>{{ scope.row.accountId | deseHandler(4, 4, '*') || '--' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="hasFile"
            label="合同附件"
            align="center"
            min-width="80"
          >
            <template slot-scope="scope">
              <p v-if="scope.row.hasFile == '0'" style="color: #6dd400">
                未上传
              </p>
              <p v-else-if="scope.row.hasFile == '1'" style="color: #e02020">
                已上传
              </p>
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            label="状态"
            align="center"
          ></el-table-column>

          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-if="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'enterpriseStaff',

  props: ['companyId', 'qyName', 'qyUscc'],
  data() {
    return {
      // 工资卡下拉框
      hasAccountOptions: [
        { id: '1', text: '已填写' },
        { id: '0', text: '未填写' },
      ],
      //下拉框数据
      hasFileOptions: [
        { id: '1', text: '已上传' },
        { id: '0', text: '未上传' },
      ],
      hasJob: [
        { id: 'ON_JOB', text: '在职' },
        { id: 'DISMISSED', text: '离职' },
      ],
      //表格数据
      employeeoutList: [],
      requestUrl: 'api-e/nc/employee/expand/all',
      advanced: false,
      date: [], //日期区间
      //搜索条件
      filterField: {
        companyId: this.companyId,
        createTimeStart: '',
        createTimeEnd: '',
        keyword: '', //姓名
        hasAccount: '', //有无工资卡
        hasFile: '', //有无合同附件
        status: '',
      },
      isShow: false, //列表加载
      loading: true,
    }
  },
  created() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    getTableList(data) {
      this.employeeoutList = data
      this.loading = false
      if (this.employeeoutList.length < 1) {
        this.isShow = true
      }
    },
    // 搜索
    searchList() {
      this.filterField.companyId = this.companyId
      if (this.date) {
        this.filterField.createTimeStart = this.date[0]
        this.filterField.createTimeEnd = this.date[1]
      } else {
        this.filterField.createTimeStart = ''
        this.filterField.createTimeEnd = ''
      }

      this.$refs.pagination.getTableListData()
    },
    //显示人员详情传参
    // toEmployeeDetail(index, row) {
    //     this.employeeId = row.id;
    //     this.$router.push({
    //         path: "/home/employee/employeeDetail/",
    //         name: "employeeDetail",
    //         params: {
    //             employeeId: this.employeeId,
    //             contractId: row.contractId
    //         }
    //     });
    // },
    toEmployeeDetail(index, row) {
      this.employeeId = row.id
      this.$router.push({
        path: '/home/employee/monitorEmployeeDetail/',
        name: 'monitorEmployeeDetail',
        query: {
          employeeId: this.employeeId,
          companyId: this.companyId,
          name: 'enterpriseStaff',
          qyName: this.qyName,
          qyUscc: this.qyUscc,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/businessManagement/settledEnterprise',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.container {
  .mainCon {
    top: 0;
  }
}
.mainBox {
  padding: 20px 0px !important;
}
@import '../../../static/css/filterArea.less';
</style>
